// pages/shop/shop.js
Page({

  /**
   * 页面的初始数据
   */
    data: {
        goodsList:[
            {
                id:1,
                title:"埃菲强化营养谷宝 强化营养谷物膳强化营养谷食 埃菲强化营养谷宝  中科特膳",
                price:"214元",
                imgUrl:"/resources/shop/goods-img.png"
            },
            {
                id:2,
                title:"埃菲强化营养谷宝 强化营养谷物膳强化营养谷食 中科特膳",
                price:"2244元",
                imgUrl:"/resources/shop/goods-img.png"
            },
            {
                id:2,
                title:"埃菲强化营养谷宝 强化营养谷物膳强化营养谷食 中科特膳",
                price:"2244元",
                imgUrl:"/resources/shop/goods-img.png"
            },
            {
                id:2,
                title:"埃菲强化营养谷宝 强化营养谷物膳强化营养谷食 中科特膳",
                price:"2244元",
                imgUrl:"/resources/shop/goods-img.png"
            },
            {
                id:2,
                title:"埃菲强化营养谷宝 强化营养谷物膳强化营养谷食 中科特膳",
                price:"2244元",
                imgUrl:"/resources/shop/goods-img.png"
            }

        ],
          goodsList01:[
              {
                  id:1,
                  title:"强化营养谷物膳强化营养谷食 埃菲强化营养谷宝  中科特膳",
                  price:"14元",
                  imgUrl:"/resources/shop/goods-img.png"
              },
              {
                  id:2,
                  title:"埃菲强化营养谷宝 强化营养谷物膳强化营养谷食 中科特膳",
                  price:"22元",
                  imgUrl:"/resources/shop/goods-img.png"
              },
              {
                  id:3,
                  title:"埃菲强化营养谷宝 强化营养谷物膳强化营养谷食 中科特膳",
                  price:"2元",
                  imgUrl:"/resources/shop/goods-img.png"
              }

          ],
        navList:[
            {
                nav:"医用食品",
                icon:"/resources/shop/yysp.png",
                iconCur:"/resources/shop/yysp-cur.png"
            },{
                nav:"检测服务",
                icon:"/resources/shop/jcfu.png",
                iconCur:"/resources/shop/jcfu-cur.png"
            },{
                nav:"健康套餐",
                icon:"/resources/shop/tc.png",
                iconCur:"/resources/shop/tc-cur.png"
            },{
                nav:"仪器设备",
                icon:"/resources/shop/ss.png",
                iconCur:"/resources/shop/ss-cur.png"
            }
        ],
        imgUrls: [
            "../../resources/shop/swiper/swiper01.jpg",
            "../../resources/shop/swiper/swiper03.jpg",
            "../../resources/shop/swiper/swiper02.png",
            "../../resources/shop/swiper/swipe04.jpg"
        ],
        indicatorDots: true,
        vertical: false,
        autoplay: true,
        circular: true,
        interval: 4000,
        duration: 500,
        previousMargin: 0,
        nextMargin: 0,
        indicatorColor:"raba(255,255,255,.3)",
        indicatorActiveColor:"#ffffff",
        imgWidth:wx.getSystemInfoSync().windowWidth,
        currentTab:0
    },
    //获取swiper 图片高度
    imgHeight:function(e){
        var winW = wx.getSystemInfoSync().windowWidth;
        var imgW = e.detail.width;
        var imgH = e.detail.height;
        var swiperH = winW*imgH/imgW+"px";
        console.log(swiperH,winW,imgH,imgW);
        this.setData({
           Height:swiperH
        })
    },
    //选择导航栏
    switchNav(event){
        var cur = event.currentTarget.dataset.current;
        if (this.data.currentTab == cur) {
            return false;
        } else {
            this.setData({
                currentTab: cur
            })
        }
        this.getContainerH();
    },
    switchTab(event){
        var cur = event.detail.current;
        this.setData({
            currentTab: cur
        });
        this.getContainerH();
    },
    //自适应swiper高度
    getContainerH:function(){
        let that = this;
        let curr;
        if(that.data.currentTab==0){
            curr = that.data.goodsList.length;
        }else if(that.data.currentTab==1){
            curr = that.data.goodsList01.length;
        }else if(that.data.currentTab==2){
            curr = that.data.goodsList.length;
        }else if(that.data.currentTab==3){
            curr = that.data.goodsList01.length;
        }
        wx.createSelectorQuery().select('.goods-item').boundingClientRect(function(res){
            console.log(res);
            console.log(curr);
            var resultLen = Math.ceil(curr/2);
            console.log(resultLen);
            console.log((res.height + 10) * resultLen);
            that.setData({
                swiperH:(res.height+10)*resultLen+20
            })
        }).exec()
    },
    //跳的详情页
    jumpToDetails:function(option){
        console.log(1,option);
        var id = option.currentTarget.dataset.id;
        console.log(id);
        wx.navigateTo({
            url:"/subPages/shopPage/details/index?id="+id
        })
    },
    /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
        this.getContainerH();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})